package cn.iocoder.yudao.module.dr.controller.admin.report;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.dr.controller.admin.report.vo.index.*;
import cn.iocoder.yudao.module.dr.controller.admin.report.vo.source.SourceCountRespVO;
import cn.iocoder.yudao.module.dr.controller.admin.report.vo.use.UseCountRespVO;
import cn.iocoder.yudao.module.dr.controller.admin.report.vo.visit.VisitCountRespVO;
import cn.iocoder.yudao.module.dr.service.collection3dacquisition.Collection3dAcquisitionService;
import cn.iocoder.yudao.module.dr.service.collectionimageacquisition.CollectionImageAcquisitionService;
import cn.iocoder.yudao.module.dr.service.collectionlinkaddress.CollectionLinkAddressService;
import cn.iocoder.yudao.module.dr.service.collectionmanagement.CollectionManagementService;
import cn.iocoder.yudao.module.dr.service.source.SourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 统计接口")
@RestController
@RequestMapping("/dr/report")
@Validated
public class ReportController {

    @Resource
    private SourceService sourceService;

    @Resource
    private CollectionManagementService collectionManagementService;


    @Resource
    private CollectionLinkAddressService collectionLinkAddressService;


    @GetMapping("/index")
    @Operation(summary = "首页统计数据")
    @PreAuthorize("@ss.hasPermission('dr:data:query')")
    public CommonResult<IndexDataRespVO> getData() {
        IndexDataRespVO result = new IndexDataRespVO();
        List<SourceTypeDataRespVO> sourceTypeDataRespVOS = collectionManagementService.countByLevel();
        result.setSourceTypeDataRespVOS(sourceTypeDataRespVOS);

        List<FileTypeDataRespVO> fileTypeDataRespVOS = collectionManagementService.countBySource();
        result.setFileTypeDataRespVOS(fileTypeDataRespVOS);


        //完残情况统计
        List<DeptUseDataRespVO> deptUseDataRespVOS = collectionManagementService.countByDegree();
        result.setDeptUseDataRespVOS(deptUseDataRespVOS);

        List<VisitDataRespVO> visitDataRespVOS =  collectionManagementService.countByCategory();
        result.setVisitDataRespVOS(visitDataRespVOS);

        return success(result);
    }


    @GetMapping("/sourceCount")
    @Operation(summary = "资源统计")
    @PreAuthorize("@ss.hasPermission('dr:data:query')")
    public CommonResult<SourceCountRespVO> sourceCount() {
        SourceCountRespVO sourceCount  = new SourceCountRespVO();

        List<SourceTypeDataRespVO> sourceTypeDataRespVOS = collectionLinkAddressService.countByImage();
        sourceCount.setSourceTypeDataRespVOS(sourceTypeDataRespVOS);

        List<FileTypeDataRespVO> fileTypeDataRespVOS = collectionLinkAddressService.countBy3d();
        sourceCount.setFileTypeDataRespVOS(fileTypeDataRespVOS);


        return success(sourceCount);
    }



    @GetMapping("/useCount")
    @Operation(summary = "使用统计")
    @PreAuthorize("@ss.hasPermission('dr:data:query')")
    public CommonResult<UseCountRespVO> useCount() {
        UseCountRespVO sourceCount  = new UseCountRespVO();

        List<SourceTypeDataRespVO> sourceTypeDataRespVOS = collectionLinkAddressService.countByImage();
        sourceCount.setSourceTypeDataRespVOS(sourceTypeDataRespVOS);

        List<FileTypeDataRespVO> fileTypeDataRespVOS =  collectionLinkAddressService.countBy3d();
        sourceCount.setFileTypeDataRespVOS(fileTypeDataRespVOS);

        List<DeptUseDataRespVO> deptUseDataRespVOS = collectionLinkAddressService.countByBizType();
        sourceCount.setDeptUseDataRespVOS(deptUseDataRespVOS);

        return success(sourceCount);
    }

    @GetMapping("/visitCount")
    @Operation(summary = "访问统计")
    @PreAuthorize("@ss.hasPermission('dr:data:query')")
    public CommonResult<VisitCountRespVO> visitCount() {
        VisitCountRespVO sourceCount  = new VisitCountRespVO();


        List<VisitMothDataRespVO> visitMothDataRespVOS =  sourceService.countVisitByMoth();
        sourceCount.setVisitMothDataRespVOS(visitMothDataRespVOS);

        List<SourceTypeDataRespVO> sourceTypeDataRespVOS = sourceService.countVisitBySourceType();
        sourceCount.setSourceTypeDataRespVOS(sourceTypeDataRespVOS);

        List<VisitDataRespVO> visitDataRespVOS = sourceService.countVisitByTime();
        sourceCount.setVisitDataRespVOS(visitDataRespVOS);

        return success(sourceCount);
    }


}